var sysPath = "";

function SetSysPath(path){
	sysPath = path;
}

function AddMainTab(id, tabs) {
	var tab = tabs.getItem(id);

	if (tab == null) {
		var _title = "";
		var _icon = "";
		var _item = "";
		if (id == "1") {
			_title = "未处理警告";
			_icon = "tip";
			_item = GetWarn(1);
		} else if (id == "2") {
			_title = "已处理警告";
			_icon = "tip";
			_item = GetWarn(2);
		} else if (id == "3") {
			_title = "全部警告";
			__icon = "tip";
			_item = GetWarn(3);
		} else if (id == "4" || (parseInt(id) > 1000 && parseInt(id) < 2000)) {
			_title = "警告报表";
			_icon = "count";
			_item = GetWarn_Report();
		} else if (id == "5") {
			_title = "全部日志";
			_icon = "log";
			_item = GetLogs();
		} else if (id == "6"|| (parseInt(id) > 6000 && parseInt(id) < 7000)) {
			_title = "日志报表";
			_icon = "count";
			_item = GetLog_Report();
		} else if (id == "7") {
			_title = "服务器";
			_icon = "server";
			_item = GetServer();
		} else if (id == "8") {
			_title = "探测器";
			_icon = "subnet";
			_item = GetProbe();
		} else if (id == "9") {
			_title = "预警策略";
			_icon = "policy";
			_item = GetPolicy();
		} else if (id == "10") {
			_title = "运行状态";
			_icon = "flow";
			_item = GetRunning();
		} else if (id == "11") {
			_title = "备份";
			_icon = "save";
			_item = GetSysInfo();
		} else if (id == "12") {
			_title = "管理员";
			_icon = "manager";
			_item = GetManger();
		}else if (id == "13") {
			_title = "系统日志";
			_icon = "sys_log";
			_item = GetSysLogs();
		}else if (id == "14") {
			_title = "设置及热备";
			_icon = "info";
			_item = GetBackup();
		}else if (id == "15") {
			_title = "时间";
			_icon = "time";
			_item = GetDateStep();
		}else if (id == "16") {
			_title = "订阅";
			_icon = "filesend";
			_item = GetLog_Subscribe();
		}else if (id == "17") {
			_title = "订阅";
			_icon = "filesend";
			_item = GetLog_Subscribe();
		}
		
		var tab = tabs.add({
					id : id,
					title : _title,
					iconCls : _icon,
					items : [_item],
					layout : 'fit',
					border : false,
					split : true,
					autoScroll : true,
					closable : true,
			        listeners : {   
				        "destroy" : function(){   
				            if(tabs.items.length == 0){
				            	AddMainTab("1", tabs);
				            } 
				        }
				    }
				}).show();
	} else {
		tabs.setActiveTab(tab);
	}

}
function ModifyPassword() {
	var manager = new Ext.form.FormPanel({
				frame : true,
				layout : 'form',
				region : 'center',
				xtype : 'fieldset',
				bodyStyle : 'padding:10px;',
				items : [{
							xtype : 'textfield',
							name : 'manager.id',
							fieldLabel : '',
							anchor : '100%',
							hidden : true,
							hideLabel : true
						}, {
							xtype : 'textfield',
							name : 'manager.name',
							fieldLabel : '名称',
							readOnly : true,
							anchor : '100%'
						}, {
							xtype : 'textarea',
							name : 'manager.context',
							fieldLabel : '描述',
							readOnly : true,
							anchor : '100%'
						}, {
							xtype : 'textfield',
							name : 'manager.password',
							fieldLabel : '密码',
							inputType : 'password',
							anchor : '100%'
						}, {
							xtype : 'textfield',
							name : 'repassword',
							fieldLabel : '确认密码',
							inputType : 'password',
							anchor : '100%'
						}]

			});

	var title = "";
	var caption = "";
	title = "修改密码";
	caption = "修改密码";

	var mwindow = new Ext.Window({
				layout : 'border',
				width : 400,
				height : 250,
				title : title,
				modal : true,
				resizable : true,
				maximizable : true,
				iconCls : 'modifypwd',
				items : [manager],
				plain : true
			});
	mwindow.addButton({
				text : caption,
				handler : function() {
					mwindow.close();
				}
			});
	mwindow.addButton({
				text : '取 消',
				handler : function() {
					mwindow.close();
				}
			});
	mwindow.show();
}

function LogoutSystem(){
	location.href = sysPath + "/manager/Logout.do";
}

function ShowMsgTip(){
			var window = new Ext.Window({
						width : 390,
						height : 200,
						shadow : false,
						html : "欢迎登陆SEM",
						title : "温馨提示:"
					});
			function show() {
				this.el.alignTo(Ext.getBody(), 'br-br');
				this.el.slideIn('b', {
							easing : 'easeOut',
							callback : function() {
								this.close.defer(10000, this); //定时关闭窗口
							},
							scope : this,
							duration : 1
						});

			}
			function hide() {
				if (this.isClose === true) { //防止点击关闭和定时关闭处理
					return false;
				}
				this.isClose = true;
				this.el.slideOut('b', {
							easing : 'easeOut',
							callback : function() {
								this.un('beforeclose', hide, this);
								this.close();
							},
							scope : this,
							duration : 5
						});
				return false;
			}
			window.on('show', show, window);
			window.on('beforeclose', hide, window)
			window.show();
}